//
//  WYDiscover.swift
//  weibo
//
//  Created by 王玉东 on 16/4/6.
//  Copyright © 2016年 wyd. All rights reserved.
//

import UIKit

class WYDiscover: UIView {
    
    
    @IBOutlet weak var searchText: UITextField!
    @IBOutlet weak var cancleBtn: UIButton!
    @IBOutlet weak var rightTrall: NSLayoutConstraint!
//MARK:获取xib文件
  class func LoaddiscoverView()-> WYDiscover {
    
    let v = NSBundle.mainBundle().loadNibNamed("discover", owner: nil, options: nil).last as! WYDiscover
 
    return v
    }
    
    
    @IBAction func searchClick(sender: AnyObject) {
     rightTrall.constant = self.cancleBtn.frame.width
        
        UIView.animateWithDuration(0.25) { () -> Void in
            
            self.layoutIfNeeded()
        }
        
    }
//MARK:设置textfeiled的位置
    override func awakeFromNib() {
        
        self.searchText.leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        
        self.searchText.leftView?.frame = CGRectMake(0, 0, self.frame.height, self.frame.height)
        
        //设置图片居中显示
        self.searchText.leftView?.contentMode = .Center
        
        //设置leftView始终显示
        self.searchText.leftViewMode = .Always
        
        //设置TextField的样式
//        self.searchText.layer.cornerRadius = 10
//        
//        self.searchText.layer.masksToBounds = true
        
        
    }
    @IBAction func cancaleClick(sender: AnyObject) {
        
        self.rightTrall.constant = 0
        
        UIView.animateWithDuration(0.25) { () -> Void in
          self.layoutIfNeeded()
        }
        
        self.searchText.resignFirstResponder()
    }



}
